﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FonShare.Classes;
using FonShare.Classes.Data;
using FonShare.Classes.FTP;
using FonShare.Classes.Coolite;
using Coolite.Ext.Web;

namespace FonShare.WebPages
{
    public partial class SeeMyFiles : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                int userId = (int) Session[FS_Constants.Session.USERID];
                FS_DataClassesDataContext dc = new FS_DataClassesDataContext();
                FS_Server currentServer = dc.FS_Servers.Where(record => record.OwnerID == userId).First();
                List<String> myfiles = new List<string>();
                List<FS_FTPFile> myFiles = new List<FS_FTPFile>();
                try
                {
                    //myfiles = FS_FTPManager.GetFilesList(currentServer);
                    myFiles = FS_FTPManager.GetFTPFilesList(currentServer);
                }
                catch (Exception ex)
                {
                    MessageLabel.Text = "Error during connection to Server, please check your server configuration or try again.";
                }
                //MyFilesListBox.DataSource = myfiles;
                //MyFilesListBox.DataBind();
                TreePanel tree = new TreePanel();
                MyFilesPlaceHolder.Controls.Add(tree);
                Dictionary<string, List<FS_FTPFile>> myDictionary = new Dictionary<string, List<FS_FTPFile>>();
                myDictionary.Add(currentServer.ServerName, myFiles);
                FS_TreeBuilder.BuildFilesTreePanel(tree, "My Files", myDictionary);
            }
        }
    }
}
